<?php
session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg7.php" ?>
<?php include "ewmysql7.php" ?>
<?php include "phpfn7.php" ?>
<?php include "psacar_carinfo.php" ?>
<?php include "psacar_userinfo.php" ?>
<?php include "userfn7.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php
// Create page object
$psacar_car_list = new cpsacar_car_list();
$Page = & $psacar_car_list;

// Page init
$psacar_car_list->Page_Init();

// Page main
$psacar_car_list->Page_Main();
?>
<?php include "header.php" ?>
<?php if ($psacar_car->Export == "") { ?>
    <script type="text/javascript">
        <!--

        // Create page object
        var psacar_car_list = new ew_Page("psacar_car_list");

        // page properties
        psacar_car_list.PageID = "list"; // page ID
        psacar_car_list.FormID = "fpsacar_carlist"; // form ID
        var EW_PAGE_ID = psacar_car_list.PageID; // for backward compatibility

        // extend page with Form_CustomValidate function
        psacar_car_list.Form_CustomValidate =  
            function(fobj) { // DO NOT CHANGE THIS LINE!

            // Your custom validation code here, return false if invalid. 
            return true;
        }
    <?php if (EW_CLIENT_VALIDATE) { ?>
            psacar_car_list.ValidateRequired = true; // uses JavaScript validation
    <?php } else { ?>
            psacar_car_list.ValidateRequired = false; // no JavaScript validation
    <?php } ?>

        //-->
    </script>
    <style type="text/css">

        /* main table preview row color */
        .ewTablePreviewRow {
            background-color: inherit; /* preview row */
        }
    </style>
    <script language="JavaScript" type="text/javascript">
        <!--

        // PreviewRow extension
        var ew_AjaxDetailsTimer = null;
        var EW_PREVIEW_SINGLE_ROW = false;
        var EW_PREVIEW_IMAGE_CLASSNAME = "ewPreviewRowImage";
        var EW_PREVIEW_SHOW_IMAGE = "images/expand.gif";
        var EW_PREVIEW_HIDE_IMAGE = "images/collapse.gif";
        var EW_PREVIEW_LOADING_IMAGE = "images/loading.gif";
        var EW_PREVIEW_LOADING_TEXT = ewLanguage.Phrase("Loading"); // lang phrase for loading

        // add row
        function ew_AddRowToTable(r) {
            var row, cell;
            var tb = ewDom.getAncestorByTagName(r, "TBODY");
            if (EW_PREVIEW_SINGLE_ROW) {
                row = ewDom.getElementBy(function(node) { return ewDom.hasClass(node, EW_TABLE_PREVIEW_ROW_CLASSNAME)}, "TR", tb);
                ew_RemoveRowFromTable(row);
            }
            var sr = ewDom.getNextSiblingBy(r, function(node) { return node.tagName == "TR"});
            if (sr && ewDom.hasClass(sr, EW_TABLE_PREVIEW_ROW_CLASSNAME)) {
                row = sr; // existing sibling row
                if (row && row.cells && row.cells[0])
                    cell = row.cells[0];
            } else {
                row = tb.insertRow(r.rowIndex); // new row
                if (row) {
                    row.className = EW_TABLE_PREVIEW_ROW_CLASSNAME;
                    var cell = row.insertCell(0);
                    cell.style.borderRight = "0";
                    var colcnt = r.cells.length;
                    if (r.cells) {
                        var spancnt = 0;
                        for (var i = 0; i < colcnt; i++)
                            spancnt += r.cells[i].colSpan;
                        if (spancnt > 0)
                            cell.colSpan = spancnt;
                    }
                    var pt = ewDom.getAncestorByTagName(row, "TABLE");
                    if (pt) ew_SetupTable(pt);
                }
            }
            if (cell)
                cell.innerHTML = "<img src=\"" + EW_PREVIEW_LOADING_IMAGE + "\" style=\"border: 0; vertical-align: middle;\"> " + EW_PREVIEW_LOADING_TEXT;
            return row;
        }

        // remove row
        function ew_RemoveRowFromTable(r) {
            if (r && r.parentNode)
                r.parentNode.removeChild(r);
        }

        // show results in new table row
        var ew_AjaxHandleSuccess2 = function(o) {
            if (o.responseText !== undefined) {
                var row = o.argument.row;
                if (!row || !row.cells || !row.cells[0]) return;
                row.cells[0].innerHTML = o.responseText;
                var ct = ewDom.getElementBy(function(node) { return ewDom.hasClass(node, EW_TABLE_CLASS)}, "TABLE", row);
                if (ct) ew_SetupTable(ct);

                //clearTimeout(ew_AjaxDetailsTimer);
                //setTimeout("alert(ew_AjaxDetailsTimer);", 500);

            }
        }

        // show error in new table row
        var ew_AjaxHandleFailure2 = function(o) {
            var row = o.argument.row;
            if (!row || !row.cells || !row.cells[0]) return;
            row.cells[0].innerHTML = o.responseText;
        }

        // show detail preview by table row expansion
        function ew_AjaxShowDetails2(ev, link, url) {
            var img = ewDom.getElementBy(function(node) { return true; }, "IMG", link);
            var r = ewDom.getAncestorByTagName(link, "TR");
            if (!img || !r)
                return;
            var show = (img.src.substr(img.src.length - EW_PREVIEW_SHOW_IMAGE.length) == EW_PREVIEW_SHOW_IMAGE);
            if (show) {
                if (ew_AjaxDetailsTimer)
                    clearTimeout(ew_AjaxDetailsTimer);		
                var row = ew_AddRowToTable(r);
                ew_AjaxDetailsTimer = setTimeout(function() { ewConnect.asyncRequest('GET', url, {success: ew_AjaxHandleSuccess2, failure: ew_AjaxHandleFailure2, argument:{id: link, row: row}}) }, 200);
                ewDom.getElementsByClassName(EW_PREVIEW_IMAGE_CLASSNAME, "IMG", r, function(node) {node.src = EW_PREVIEW_SHOW_IMAGE});
                img.src = EW_PREVIEW_HIDE_IMAGE;
            } else {	 
                var sr = ewDom.getNextSiblingBy(r, function(node) { return node.tagName == "TR"});
                if (sr && ewDom.hasClass(sr, EW_TABLE_PREVIEW_ROW_CLASSNAME))
                    ew_RemoveRowFromTable(sr);
                img.src = EW_PREVIEW_SHOW_IMAGE;
            }
        }

        //-->
    </script>
    <script type="text/javascript">
        <!--
        var ew_DHTMLEditors = [];

        //-->
    </script>
    <script language="JavaScript" type="text/javascript">
        <!--

        // Write your client script here, no need to add script tags.
        // To include another .js script, use:
        // ew_ClientScriptInclude("my_javascript.js"); 
        //-->

    </script>
<?php } ?>
<?php if ($psacar_car->Export == "") { ?>
<?php } ?>
<?php
$bSelectLimit = EW_SELECT_LIMIT;
if ($bSelectLimit) {
    $psacar_car_list->lTotalRecs = $psacar_car->SelectRecordCount();
} else {
    if ($rs = $psacar_car_list->LoadRecordset())
        $psacar_car_list->lTotalRecs = $rs->RecordCount();
}
$psacar_car_list->lStartRec = 1;
if ($psacar_car_list->lDisplayRecs <= 0 || ($psacar_car->Export <> "" && $psacar_car->ExportAll)) // Display all records
    $psacar_car_list->lDisplayRecs = $psacar_car_list->lTotalRecs;
if (!($psacar_car->Export <> "" && $psacar_car->ExportAll))
    $psacar_car_list->SetUpStartRec(); // Set up start record position
if ($bSelectLimit)
    $rs = $psacar_car_list->LoadRecordset($psacar_car_list->lStartRec - 1, $psacar_car_list->lDisplayRecs);
?>
<p><span class="phpmaker" style="white-space: nowrap;"><?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $psacar_car->TableCaption() ?>
        <?php if ($psacar_car->Export == "" && $psacar_car->CurrentAction == "") { ?>
            &nbsp;&nbsp;<a href="<?php echo $psacar_car_list->ExportPrintUrl ?>"><img src="images/print.gif" alt="<?php echo ew_HtmlEncode($Language->Phrase("PrinterFriendly")) ?>" title="<?php echo ew_HtmlEncode($Language->Phrase("PrinterFriendly")) ?>" width="16" height="16" border="0"></a>
            &nbsp;&nbsp;<a href="<?php echo $psacar_car_list->ExportExcelUrl ?>"><img src='images/exportxls.gif' alt='<?php echo ew_HtmlEncode($Language->Phrase("ExportToExcel")) ?>' title='<?php echo ew_HtmlEncode($Language->Phrase("ExportToExcel")) ?>' width='16' height='16' border='0'></a>
        <?php } ?>
    </span></p>
<?php if ($Security->IsLoggedIn()) { ?>
    <?php if ($psacar_car->Export == "" && $psacar_car->CurrentAction == "") { ?>
        <a href="javascript:ew_ToggleSearchPanel(psacar_car_list);" style="text-decoration: none;"><img id="psacar_car_list_SearchImage" src="images/collapse.gif" alt="" width="9" height="9" border="0"></a><span class="phpmaker">&nbsp;<?php echo $Language->Phrase("Search") ?></span><br>
        <div id="psacar_car_list_SearchPanel">
            <form name="fpsacar_carlistsrch" id="fpsacar_carlistsrch" class="ewForm" action="<?php echo ew_CurrentPage() ?>">
                <input type="hidden" id="t" name="t" value="psacar_car">
                <table class="ewBasicSearch">
                    <tr>
                        <td><span class="phpmaker">
                                <input type="text" name="<?php echo EW_TABLE_BASIC_SEARCH ?>" id="<?php echo EW_TABLE_BASIC_SEARCH ?>" size="20" value="<?php echo ew_HtmlEncode($psacar_car->getSessionBasicSearchKeyword()) ?>">
                                <input type="Submit" name="Submit" id="Submit" value="<?php echo ew_BtnCaption($Language->Phrase("QuickSearchBtn")) ?>">&nbsp;
                                <a href="<?php echo $psacar_car_list->PageUrl() ?>cmd=reset"><?php echo $Language->Phrase("ShowAll") ?></a>&nbsp;
                            </span></td>
                    </tr>
                    <tr>
                        <td><span class="phpmaker"><label><input type="radio" name="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" id="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" value=""<?php if ($psacar_car->getSessionBasicSearchType() == "") { ?> checked="checked"<?php } ?>><?php echo $Language->Phrase("ExactPhrase") ?></label>&nbsp;&nbsp;<label><input type="radio" name="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" id="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" value="AND"<?php if ($psacar_car->getSessionBasicSearchType() == "AND") { ?> checked="checked"<?php } ?>><?php echo $Language->Phrase("AllWord") ?></label>&nbsp;&nbsp;<label><input type="radio" name="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" id="<?php echo EW_TABLE_BASIC_SEARCH_TYPE ?>" value="OR"<?php if ($psacar_car->getSessionBasicSearchType() == "OR") { ?> checked="checked"<?php } ?>><?php echo $Language->Phrase("AnyWord") ?></label></span></td>
                    </tr>
                </table>
            </form>
        </div>
    <?php } ?>
<?php } ?>
<?php
if (EW_DEBUG_ENABLED)
    echo ew_DebugMsg();
$psacar_car_list->ShowMessage();
?>
<br>
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
            <form name="fpsacar_carlist" id="fpsacar_carlist" class="ewForm" action="" method="post">
                <div id="gmp_psacar_car" class="ewGridMiddlePanel">
                    <?php if ($psacar_car_list->lTotalRecs > 0) { ?>
                        <table cellspacing="0" rowhighlightclass="ewTableHighlightRow" rowselectclass="ewTableSelectRow" roweditclass="ewTableEditRow" class="ewTable ewTableSeparate">
                            <?php echo $psacar_car->TableCustomInnerHtml ?>
                            <thead><!-- Table header -->
                                <tr class="ewTableHeader">
                                    <?php
// Render list options
                                    $psacar_car_list->RenderListOptions();

// Render list options (header, left)
                                    $psacar_car_list->ListOptions->Render("header", "left");
                                    ?>
                                    <?php if ($psacar_car->id->Visible) { // id ?>
                                        <?php if ($psacar_car->SortUrl($psacar_car->id) == "") { ?>
                                            <td><?php echo $psacar_car->id->FldCaption() ?></td>
                                        <?php } else { ?>
                                            <td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $psacar_car->SortUrl($psacar_car->id) ?>',1);">
                                                    <table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $psacar_car->id->FldCaption() ?></td><td style="width: 10px;"><?php if ($psacar_car->id->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($psacar_car->id->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
                                                </div></td>		
        <?php } ?>
                                    <?php } ?>		
                                    <?php if ($psacar_car->dealer_id->Visible) { // dealer_id ?>
                                        <?php if ($psacar_car->SortUrl($psacar_car->dealer_id) == "") { ?>
                                            <td><?php echo $psacar_car->dealer_id->FldCaption() ?></td>
                                        <?php } else { ?>
                                            <td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $psacar_car->SortUrl($psacar_car->dealer_id) ?>',1);">
                                                    <table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $psacar_car->dealer_id->FldCaption() ?></td><td style="width: 10px;"><?php if ($psacar_car->dealer_id->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($psacar_car->dealer_id->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
                                                </div></td>		
        <?php } ?>
                                    <?php } ?>		
                                    <?php if ($psacar_car->model_id->Visible) { // model_id ?>
                                        <?php if ($psacar_car->SortUrl($psacar_car->model_id) == "") { ?>
                                            <td><?php echo $psacar_car->model_id->FldCaption() ?></td>
                                        <?php } else { ?>
                                            <td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $psacar_car->SortUrl($psacar_car->model_id) ?>',1);">
                                                    <table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $psacar_car->model_id->FldCaption() ?></td><td style="width: 10px;"><?php if ($psacar_car->model_id->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($psacar_car->model_id->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
                                                </div></td>		
        <?php } ?>
                                    <?php } ?>		
                                    <?php if ($psacar_car->year->Visible) { // year ?>
                                        <?php if ($psacar_car->SortUrl($psacar_car->year) == "") { ?>
                                            <td><?php echo $psacar_car->year->FldCaption() ?></td>
                                        <?php } else { ?>
                                            <td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $psacar_car->SortUrl($psacar_car->year) ?>',1);">
                                                    <table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $psacar_car->year->FldCaption() ?></td><td style="width: 10px;"><?php if ($psacar_car->year->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($psacar_car->year->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
                                                </div></td>		
        <?php } ?>
                                    <?php } ?>		
                                    <?php if ($psacar_car->type_id->Visible) { // type_id ?>
                                        <?php if ($psacar_car->SortUrl($psacar_car->type_id) == "") { ?>
                                            <td><?php echo $psacar_car->type_id->FldCaption() ?></td>
                                        <?php } else { ?>
                                            <td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $psacar_car->SortUrl($psacar_car->type_id) ?>',1);">
                                                    <table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $psacar_car->type_id->FldCaption() ?></td><td style="width: 10px;"><?php if ($psacar_car->type_id->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($psacar_car->type_id->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
                                                </div></td>		
        <?php } ?>
                                    <?php } ?>		
                                    <?php if ($psacar_car->category_id->Visible) { // category_id ?>
                                        <?php if ($psacar_car->SortUrl($psacar_car->category_id) == "") { ?>
                                            <td><?php echo $psacar_car->category_id->FldCaption() ?></td>
                                        <?php } else { ?>
                                            <td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $psacar_car->SortUrl($psacar_car->category_id) ?>',1);">
                                                    <table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $psacar_car->category_id->FldCaption() ?></td><td style="width: 10px;"><?php if ($psacar_car->category_id->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($psacar_car->category_id->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
                                                </div></td>		
        <?php } ?>
                                    <?php } ?>		
                                    <?php if ($psacar_car->price->Visible) { // price ?>
                                        <?php if ($psacar_car->SortUrl($psacar_car->price) == "") { ?>
                                            <td><?php echo $psacar_car->price->FldCaption() ?></td>
                                        <?php } else { ?>
                                            <td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $psacar_car->SortUrl($psacar_car->price) ?>',1);">
                                                    <table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $psacar_car->price->FldCaption() ?></td><td style="width: 10px;"><?php if ($psacar_car->price->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($psacar_car->price->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
                                                </div></td>		
        <?php } ?>
                                    <?php } ?>		
                                    <?php if ($psacar_car->quality->Visible) { // quality ?>
                                        <?php if ($psacar_car->SortUrl($psacar_car->quality) == "") { ?>
                                            <td style="white-space: nowrap;"><?php echo $psacar_car->quality->FldCaption() ?></td>
                                        <?php } else { ?>
                                            <td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $psacar_car->SortUrl($psacar_car->quality) ?>',1);">
                                                    <table cellspacing="0" class="ewTableHeaderBtn" style="white-space: nowrap;"><thead><tr><td><?php echo $psacar_car->quality->FldCaption() ?></td><td style="width: 10px;"><?php if ($psacar_car->quality->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($psacar_car->quality->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
                                                </div></td>		
        <?php } ?>
                                    <?php } ?>		
                                    <?php if ($psacar_car->fuel->Visible) { // fuel ?>
                                        <?php if ($psacar_car->SortUrl($psacar_car->fuel) == "") { ?>
                                            <td><?php echo $psacar_car->fuel->FldCaption() ?></td>
                                        <?php } else { ?>
                                            <td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $psacar_car->SortUrl($psacar_car->fuel) ?>',1);">
                                                    <table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $psacar_car->fuel->FldCaption() ?></td><td style="width: 10px;"><?php if ($psacar_car->fuel->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($psacar_car->fuel->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
                                                </div></td>		
        <?php } ?>
                                    <?php } ?>		
                                    <?php
                                    /*
                                      if ($psacar_car->rent_type->Visible) { // rent_type ?>
                                      <?php if ($psacar_car->SortUrl($psacar_car->rent_type) == "") { ?>
                                      <td><?php echo $psacar_car->rent_type->FldCaption() ?></td>
                                      <?php } else { ?>
                                      <td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $psacar_car->SortUrl($psacar_car->rent_type) ?>',1);">
                                      <table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $psacar_car->rent_type->FldCaption() ?></td><td style="width: 10px;"><?php if ($psacar_car->rent_type->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($psacar_car->rent_type->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
                                      </div></td>
                                      <?php } ?>
                                      <?php }
                                     */
                                    ?>		
                                    <?php
                                    /*
                                      if ($psacar_car->vehicle_type_id->Visible) { // vehicle_type_id ?>
                                      <?php if ($psacar_car->SortUrl($psacar_car->vehicle_type_id) == "") { ?>
                                      <td><?php echo $psacar_car->vehicle_type_id->FldCaption() ?></td>
                                      <?php } else { ?>
                                      <td><div class="ewPointer" onmousedown="ew_Sort(event,'<?php echo $psacar_car->SortUrl($psacar_car->vehicle_type_id) ?>',1);">
                                      <table cellspacing="0" class="ewTableHeaderBtn"><thead><tr><td><?php echo $psacar_car->vehicle_type_id->FldCaption() ?></td><td style="width: 10px;"><?php if ($psacar_car->vehicle_type_id->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($psacar_car->vehicle_type_id->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></td></tr></thead></table>
                                      </div></td>
                                      <?php } ?>
                                      <?php }
                                     */
                                    ?>		
                                    <?php
// Render list options (header, right)
                                    $psacar_car_list->ListOptions->Render("header", "right");
                                    ?>
                                </tr>
                            </thead>
                                    <?php
                                    if ($psacar_car->ExportAll && $psacar_car->Export <> "") {
                                        $psacar_car_list->lStopRec = $psacar_car_list->lTotalRecs;
                                    } else {
                                        $psacar_car_list->lStopRec = $psacar_car_list->lStartRec + $psacar_car_list->lDisplayRecs - 1; // Set the last record to display
                                    }
                                    $psacar_car_list->lRecCount = $psacar_car_list->lStartRec - 1;
                                    if ($rs && !$rs->EOF) {
                                        $rs->MoveFirst();
                                        if (!$bSelectLimit && $psacar_car_list->lStartRec > 1)
                                            $rs->Move($psacar_car_list->lStartRec - 1);
                                    }

// Initialize aggregate
                                    $psacar_car->RowType = EW_ROWTYPE_AGGREGATEINIT;
                                    $psacar_car_list->RenderRow();
                                    $psacar_car_list->lRowCnt = 0;
                                    while (($psacar_car->CurrentAction == "gridadd" || !$rs->EOF) &&
                                    $psacar_car_list->lRecCount < $psacar_car_list->lStopRec) {
                                        $psacar_car_list->lRecCount++;
                                        if (intval($psacar_car_list->lRecCount) >= intval($psacar_car_list->lStartRec)) {
                                            $psacar_car_list->lRowCnt++;

                                            // Init row class and style
                                            $psacar_car->CssClass = "";
                                            $psacar_car->CssStyle = "";
                                            $psacar_car->RowAttrs = array('onmouseover' => 'ew_MouseOver(event, this);', 'onmouseout' => 'ew_MouseOut(event, this);', 'onclick' => 'ew_Click(event, this);');
                                            if ($psacar_car->CurrentAction == "gridadd") {
                                                $psacar_car_list->LoadDefaultValues(); // Load default values
                                            } else {
                                                $psacar_car_list->LoadRowValues($rs); // Load row values
                                            }
                                            $psacar_car->RowType = EW_ROWTYPE_VIEW; // Render view
                                            // Render row
                                            $psacar_car_list->RenderRow();

                                            // Render list options
                                            $psacar_car_list->RenderListOptions();
                                            ?>
                                    <tr<?php echo $psacar_car->RowAttributes() ?>>
                                    <?php
// Render list options (body, left)
                                    $psacar_car_list->ListOptions->Render("body", "left");
                                    ?>
                                        <?php if ($psacar_car->id->Visible) { // id ?>
                                            <td<?php echo $psacar_car->id->CellAttributes() ?>>
                                                <div<?php echo $psacar_car->id->ViewAttributes() ?>><?php echo $psacar_car->id->ListViewValue() ?></div>
                                            </td>
                                        <?php } ?>
                                        <?php if ($psacar_car->dealer_id->Visible) { // dealer_id ?>
                                            <td<?php echo $psacar_car->dealer_id->CellAttributes() ?>>
                                                <div<?php echo $psacar_car->dealer_id->ViewAttributes() ?>><?php echo $psacar_car->dealer_id->ListViewValue() ?></div>
                                            </td>
                                        <?php } ?>
                                        <?php if ($psacar_car->model_id->Visible) { // model_id ?>
                                            <td<?php echo $psacar_car->model_id->CellAttributes() ?>>
                                                <div<?php echo $psacar_car->model_id->ViewAttributes() ?>><?php echo $psacar_car->model_id->ListViewValue() ?></div>
                                            </td>
                                        <?php } ?>
                                        <?php if ($psacar_car->year->Visible) { // year ?>
                                            <td<?php echo $psacar_car->year->CellAttributes() ?>>
                                                <div<?php echo $psacar_car->year->ViewAttributes() ?>><?php echo $psacar_car->year->ListViewValue() ?></div>
                                            </td>
                                        <?php } ?>
                                        <?php if ($psacar_car->type_id->Visible) { // type_id ?>
                                            <td<?php echo $psacar_car->type_id->CellAttributes() ?>>
                                                <div<?php echo $psacar_car->type_id->ViewAttributes() ?>><?php echo $psacar_car->type_id->ListViewValue() ?></div>
                                            </td>
                                        <?php } ?>
                                        <?php if ($psacar_car->category_id->Visible) { // category_id ?>
                                            <td<?php echo $psacar_car->category_id->CellAttributes() ?>>
                                                <div<?php echo $psacar_car->category_id->ViewAttributes() ?>><?php echo $psacar_car->category_id->ListViewValue() ?></div>
                                            </td>
                                        <?php } ?>
                                        <?php if ($psacar_car->price->Visible) { // price ?>
                                            <td<?php echo $psacar_car->price->CellAttributes() ?>>
                                                <div<?php echo $psacar_car->price->ViewAttributes() ?>><?php echo $psacar_car->price->ListViewValue() ?></div>
                                            </td>
                                        <?php } ?>
                                        <?php if ($psacar_car->quality->Visible) { // quality ?>
                                            <td<?php echo $psacar_car->quality->CellAttributes() ?>>
                                                <div<?php echo $psacar_car->quality->ViewAttributes() ?>><?php echo $psacar_car->quality->ListViewValue() ?></div>
                                            </td>
                                        <?php } ?>
                                        <?php if ($psacar_car->fuel->Visible) { // fuel ?>
                                            <td<?php echo $psacar_car->fuel->CellAttributes() ?>>
                                                <div<?php echo $psacar_car->fuel->ViewAttributes() ?>><?php echo $psacar_car->fuel->ListViewValue() ?></div>
                                            </td>
                                        <?php } ?>
                                        <?php
                                        /*
                                          if ($psacar_car->rent_type->Visible) { // rent_type ?>
                                          <td<?php echo $psacar_car->rent_type->CellAttributes() ?>>
                                          <div<?php echo $psacar_car->rent_type->ViewAttributes() ?>><?php echo $psacar_car->rent_type->ListViewValue() ?></div>
                                          </td>
                                          <?php }
                                         */
                                        ?>
                                        <?php /* if ($psacar_car->vehicle_type_id->Visible) { // vehicle_type_id ?>
                                          <td<?php echo $psacar_car->vehicle_type_id->CellAttributes() ?>>
                                          <div<?php echo $psacar_car->vehicle_type_id->ViewAttributes() ?>><?php echo $psacar_car->vehicle_type_id->ListViewValue() ?></div>
                                          </td>
                                          <?php }
                                         */ ?>
                                        <?php
// Render list options (body, right)
                                        $psacar_car_list->ListOptions->Render("body", "right");
                                        ?>
                                    </tr>
                                        <?php
                                    }
                                    if ($psacar_car->CurrentAction <> "gridadd")
                                        $rs->MoveNext();
                                }
                                ?>
                            </tbody>
                        </table>
                        <?php } ?>
                </div>
            </form>
                        <?php
// Close recordset
                        if ($rs)
                            $rs->Close();
                        ?>
<?php if ($psacar_car->Export == "") { ?>
                <div class="ewGridLowerPanel">
                <?php if ($psacar_car->CurrentAction <> "gridadd" && $psacar_car->CurrentAction <> "gridedit") { ?>
                        <form name="ewpagerform" id="ewpagerform" class="ewForm" action="<?php echo ew_CurrentPage() ?>">
                            <table border="0" cellspacing="0" cellpadding="0" class="ewPager">
                                <tr>
                                    <td nowrap>
                    <?php if (!isset($psacar_car_list->Pager)) $psacar_car_list->Pager = new cPrevNextPager($psacar_car_list->lStartRec, $psacar_car_list->lDisplayRecs, $psacar_car_list->lTotalRecs) ?>
                    <?php if ($psacar_car_list->Pager->RecordCount > 0) { ?>
                                            <table border="0" cellspacing="0" cellpadding="0"><tr><td><span class="phpmaker"><?php echo $Language->Phrase("Page") ?>&nbsp;</span></td>
                                                    <!--first page button-->
            <?php if ($psacar_car_list->Pager->FirstButton->Enabled) { ?>
                                                        <td><a href="<?php echo $psacar_car_list->PageUrl() ?>start=<?php echo $psacar_car_list->Pager->FirstButton->Start ?>"><img src="images/first.gif" alt="<?php echo $Language->Phrase("PagerFirst") ?>" width="16" height="16" border="0"></a></td>
            <?php } else { ?>
                                                        <td><img src="images/firstdisab.gif" alt="<?php echo $Language->Phrase("PagerFirst") ?>" width="16" height="16" border="0"></td>
                                            <?php } ?>
                                                    <!--previous page button-->
            <?php if ($psacar_car_list->Pager->PrevButton->Enabled) { ?>
                                                        <td><a href="<?php echo $psacar_car_list->PageUrl() ?>start=<?php echo $psacar_car_list->Pager->PrevButton->Start ?>"><img src="images/prev.gif" alt="<?php echo $Language->Phrase("PagerPrevious") ?>" width="16" height="16" border="0"></a></td>
                                                    <?php } else { ?>
                                                        <td><img src="images/prevdisab.gif" alt="<?php echo $Language->Phrase("PagerPrevious") ?>" width="16" height="16" border="0"></td>
                                                    <?php } ?>
                                                    <!--current page number-->
                                                    <td><input type="text" name="<?php echo EW_TABLE_PAGE_NO ?>" id="<?php echo EW_TABLE_PAGE_NO ?>" value="<?php echo $psacar_car_list->Pager->CurrentPage ?>" size="4"></td>
                                                    <!--next page button-->
                                                    <?php if ($psacar_car_list->Pager->NextButton->Enabled) { ?>
                                                        <td><a href="<?php echo $psacar_car_list->PageUrl() ?>start=<?php echo $psacar_car_list->Pager->NextButton->Start ?>"><img src="images/next.gif" alt="<?php echo $Language->Phrase("PagerNext") ?>" width="16" height="16" border="0"></a></td>	
                                                    <?php } else { ?>
                                                        <td><img src="images/nextdisab.gif" alt="<?php echo $Language->Phrase("PagerNext") ?>" width="16" height="16" border="0"></td>
                                                    <?php } ?>
                                                    <!--last page button-->
            <?php if ($psacar_car_list->Pager->LastButton->Enabled) { ?>
                                                        <td><a href="<?php echo $psacar_car_list->PageUrl() ?>start=<?php echo $psacar_car_list->Pager->LastButton->Start ?>"><img src="images/last.gif" alt="<?php echo $Language->Phrase("PagerLast") ?>" width="16" height="16" border="0"></a></td>	
                                                    <?php } else { ?>
                                                        <td><img src="images/lastdisab.gif" alt="<?php echo $Language->Phrase("PagerLast") ?>" width="16" height="16" border="0"></td>
                                                    <?php } ?>
                                                    <td><span class="phpmaker">&nbsp;<?php echo $Language->Phrase("of") ?>&nbsp;<?php echo $psacar_car_list->Pager->PageCount ?></span></td>
                                                </tr></table>
                                        </td>	
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                        <td>
                                            <span class="phpmaker"><?php echo $Language->Phrase("Record") ?>&nbsp;<?php echo $psacar_car_list->Pager->FromIndex ?>&nbsp;<?php echo $Language->Phrase("To") ?>&nbsp;<?php echo $psacar_car_list->Pager->ToIndex ?>&nbsp;<?php echo $Language->Phrase("Of") ?>&nbsp;<?php echo $psacar_car_list->Pager->RecordCount ?></span>
                                                <?php } else { ?>
                                                    <?php if ($psacar_car_list->sSrchWhere == "0=101") { ?>
                                                <span class="phpmaker"><?php echo $Language->Phrase("EnterSearchCriteria") ?></span>
            <?php } else { ?>
                                                <span class="phpmaker"><?php echo $Language->Phrase("NoRecord") ?></span>
            <?php } ?>
        <?php } ?>
                                    </td>
                                </tr>
                            </table>
                        </form>
                                    <?php } ?>
                                    <?php //if ($psacar_car_list->lTotalRecs > 0) {  ?>
                    <span class="phpmaker">
                                    <?php if ($Security->IsLoggedIn()) { ?>
                            <a href="<?php echo $psacar_car_list->AddUrl ?>"><?php echo $Language->Phrase("AddLink") ?></a>&nbsp;&nbsp;
    <?php } ?>
                    </span>
                    <?php //}  ?>
                </div>
                <?php } ?>
        </td></tr></table>
                    <?php if ($psacar_car->Export == "" && $psacar_car->CurrentAction == "") { ?>
                    <?php } ?>
                    <?php if ($psacar_car->Export == "") { ?>
    <script language="JavaScript" type="text/javascript">
        <!--

        // Write your table-specific startup script here
        // document.write("page loaded");
        //-->

    </script>
<?php } ?>
<?php include "footer.php" ?>
<?php
$psacar_car_list->Page_Terminate();
?>
<?php

//
// Page class
//
class cpsacar_car_list {

    // Page ID
    var $PageID = 'list';
    // Table name
    var $TableName = 'psacar_car';
    // Page object name
    var $PageObjName = 'psacar_car_list';

    // Page name
    function PageName() {
        return ew_CurrentPage();
    }

    // Page URL
    function PageUrl() {
        $PageUrl = ew_CurrentPage() . "?";
        global $psacar_car;
        if ($psacar_car->UseTokenInUrl)
            $PageUrl .= "t=" . $psacar_car->TableVar . "&"; // Add page token
        return $PageUrl;
    }

    // Page URLs
    var $AddUrl;
    var $EditUrl;
    var $CopyUrl;
    var $DeleteUrl;
    var $ViewUrl;
    var $ListUrl;
    // Export URLs
    var $ExportPrintUrl;
    var $ExportHtmlUrl;
    var $ExportExcelUrl;
    var $ExportWordUrl;
    var $ExportXmlUrl;
    var $ExportCsvUrl;
    // Update URLs
    var $InlineAddUrl;
    var $InlineCopyUrl;
    var $InlineEditUrl;
    var $GridAddUrl;
    var $GridEditUrl;
    var $MultiDeleteUrl;
    var $MultiUpdateUrl;

    // Message
    function getMessage() {
        return @$_SESSION[EW_SESSION_MESSAGE];
    }

    function setMessage($v) {
        if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Append
            $_SESSION[EW_SESSION_MESSAGE] .= "<br>" . $v;
        } else {
            $_SESSION[EW_SESSION_MESSAGE] = $v;
        }
    }

    // Show message
    function ShowMessage() {
        $sMessage = $this->getMessage();
        $this->Message_Showing($sMessage);
        if ($sMessage <> "") { // Message in Session, display
            echo "<p><span class=\"ewMessage\">" . $sMessage . "</span></p>";
            $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
        }
    }

    // Validate page request
    function IsPageRequest() {
        global $objForm, $psacar_car;
        if ($psacar_car->UseTokenInUrl) {
            if ($objForm)
                return ($psacar_car->TableVar == $objForm->GetValue("t"));
            if (@$_GET["t"] <> "")
                return ($psacar_car->TableVar == $_GET["t"]);
        } else {
            return TRUE;
        }
    }

    //
    // Page class constructor
    //
	function cpsacar_car_list() {
        global $conn, $Language;

        // Language object
        $Language = new cLanguage();

        // Table object (psacar_car)
        $GLOBALS["psacar_car"] = new cpsacar_car();

        // Initialize URLs
        $this->ExportPrintUrl = $this->PageUrl() . "export=print";
        $this->ExportExcelUrl = $this->PageUrl() . "export=excel";
        $this->ExportWordUrl = $this->PageUrl() . "export=word";
        $this->ExportHtmlUrl = $this->PageUrl() . "export=html";
        $this->ExportXmlUrl = $this->PageUrl() . "export=xml";
        $this->ExportCsvUrl = $this->PageUrl() . "export=csv";
        $this->AddUrl = $GLOBALS["psacar_car"]->AddUrl();
        $this->InlineAddUrl = $this->PageUrl() . "a=add";
        $this->GridAddUrl = $this->PageUrl() . "a=gridadd";
        $this->GridEditUrl = $this->PageUrl() . "a=gridedit";
        $this->MultiDeleteUrl = "psacar_cardelete.php";
        $this->MultiUpdateUrl = "psacar_carupdate.php";

        // Table object (psacar_user)
        $GLOBALS['psacar_user'] = new cpsacar_user();

        // Page ID
        if (!defined("EW_PAGE_ID"))
            define("EW_PAGE_ID", 'list', TRUE);

        // Table name (for backward compatibility)
        if (!defined("EW_TABLE_NAME"))
            define("EW_TABLE_NAME", 'psacar_car', TRUE);

        // Start timer
        $GLOBALS["gsTimer"] = new cTimer();

        // Open connection
        $conn = ew_Connect();

        // List options
        $this->ListOptions = new cListOptions();
    }

    // 
    //  Page_Init
    //
	function Page_Init() {
        global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;
        global $psacar_car;

        // Security
        $Security = new cAdvancedSecurity();
        if (!$Security->IsLoggedIn())
            $Security->AutoLogin();
        if (!$Security->IsLoggedIn()) {
            $Security->SaveLastUrl();
            $this->Page_Terminate("login.php");
        }

        // Get export parameters
        if (@$_GET["export"] <> "") {
            $psacar_car->Export = $_GET["export"];
        } elseif (ew_IsHttpPost()) {
            if (@$_POST["exporttype"] <> "")
                $psacar_car->Export = $_POST["exporttype"];
        } else {
            $psacar_car->setExportReturnUrl(ew_CurrentUrl());
        }
        $gsExport = $psacar_car->Export; // Get export parameter, used in header
        $gsExportFile = $psacar_car->TableVar; // Get export file, used in header
        if (in_array($psacar_car->Export, array("html", "email", "excel", "word")))
            echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
        if ($psacar_car->Export == "excel") {
            header('Content-Type: application/vnd.ms-excel;charset=utf-8');
            header('Content-Disposition: attachment; filename=' . $gsExportFile . '.xls');
        }

        // Global Page Loading event (in userfn*.php)
        Page_Loading();

        // Page Load event
        $this->Page_Load();
    }

    //
    // Page_Terminate
    //
	function Page_Terminate($url = "") {
        global $conn;

        // Page Unload event
        $this->Page_Unload();

        // Global Page Unloaded event (in userfn*.php)
        Page_Unloaded();

        // Close connection
        $conn->Close();

        // Go to URL if specified
        $this->Page_Redirecting($url);
        if ($url <> "") {
            if (!EW_DEBUG_ENABLED && ob_get_length())
                ob_end_clean();
            header("Location: " . $url);
        }
        exit();
    }

    // Class variables
    var $ListOptions; // List options
    var $lDisplayRecs = 20;
    var $lStartRec;
    var $lStopRec;
    var $lTotalRecs = 0;
    var $lRecRange = 10;
    var $sSrchWhere = ""; // Search WHERE clause
    var $lRecCnt = 0; // Record count
    var $lEditRowCnt;
    var $lRowCnt;
    var $lRowIndex; // Row index
    var $lRecPerRow = 0;
    var $lColCnt = 0;
    var $sDbMasterFilter = ""; // Master filter
    var $sDbDetailFilter = ""; // Detail filter
    var $bMasterRecordExists;
    var $sMultiSelectKey;
    var $RestoreSearch;

    //
    // Page main
    //
	function Page_Main() {
        global $objForm, $Language, $gsSearchError, $Security, $psacar_car;

        // Search filters
        $sSrchAdvanced = ""; // Advanced search filter
        $sSrchBasic = ""; // Basic search filter
        $sFilter = "";
        if ($this->IsPageRequest()) { // Validate request
            // Handle reset command
            $this->ResetCmd();

            // Set up list options
            $this->SetupListOptions();

            // Get basic search values
            $this->LoadBasicSearchValues();

            // Restore search parms from Session
            $this->RestoreSearchParms();

            // Call Recordset SearchValidated event
            $psacar_car->Recordset_SearchValidated();

            // Set up sorting order
            $this->SetUpSortOrder();

            // Get basic search criteria
            if ($gsSearchError == "")
                $sSrchBasic = $this->BasicSearchWhere();
        }

        // Restore display records
        if ($psacar_car->getRecordsPerPage() <> "") {
            $this->lDisplayRecs = $psacar_car->getRecordsPerPage(); // Restore from Session
        } else {
            $this->lDisplayRecs = 20; // Load default
        }

        // Load Sorting Order
        $this->LoadSortOrder();

        // Build search criteria
        if ($sSrchAdvanced <> "")
            $this->sSrchWhere = ($this->sSrchWhere <> "") ? "(" . $this->sSrchWhere . ") AND (" . $sSrchAdvanced . ")" : $sSrchAdvanced;
        if ($sSrchBasic <> "")
            $this->sSrchWhere = ($this->sSrchWhere <> "") ? "(" . $this->sSrchWhere . ") AND (" . $sSrchBasic . ")" : $sSrchBasic;

        // Call Recordset_Searching event
        $psacar_car->Recordset_Searching($this->sSrchWhere);

        // Save search criteria
        if ($this->sSrchWhere <> "") {
            if ($sSrchBasic == "")
                $this->ResetBasicSearchParms();
            $psacar_car->setSearchWhere($this->sSrchWhere); // Save to Session
            if (!$this->RestoreSearch) {
                $this->lStartRec = 1; // Reset start record counter
                $psacar_car->setStartRecordNumber($this->lStartRec);
            }
        } else {
            $this->sSrchWhere = $psacar_car->getSearchWhere();
        }

        // Build filter
        $sFilter = "";
        if ($this->sDbDetailFilter <> "")
            $sFilter = ($sFilter <> "") ? "(" . $sFilter . ") AND (" . $this->sDbDetailFilter . ")" : $this->sDbDetailFilter;
        if ($this->sSrchWhere <> "")
            $sFilter = ($sFilter <> "") ? "(" . $sFilter . ") AND (" . $this->sSrchWhere . ")" : $this->sSrchWhere;

        // Set up filter in session
        $psacar_car->setSessionWhere($sFilter);
        $psacar_car->CurrentFilter = "";

        // Export data only
        if (in_array($psacar_car->Export, array("html", "word", "excel", "xml", "csv", "email"))) {
            $this->ExportData();
            if ($psacar_car->Export <> "email")
                $this->Page_Terminate(); // Terminate response
            exit();
        }
    }

    // Return basic search SQL
    function BasicSearchSQL($Keyword) {
        global $psacar_car;
        $sKeyword = ew_AdjustSql($Keyword);
        $sWhere = "";
        $this->BuildBasicSearchSQL($sWhere, $psacar_car->description, $Keyword);
        $this->BuildBasicSearchSQL($sWhere, $psacar_car->fuel, $Keyword);
        $this->BuildBasicSearchSQL($sWhere, $psacar_car->image, $Keyword);
        $this->BuildBasicSearchSQL($sWhere, $psacar_car->vehicle_id_number, $Keyword);
        $this->BuildBasicSearchSQL($sWhere, $psacar_car->code, $Keyword);        
        return $sWhere;
    }

    // Build basic search SQL
    function BuildBasicSearchSql(&$Where, &$Fld, $Keyword) {
        $sFldExpression = ($Fld->FldVirtualExpression <> "") ? $Fld->FldVirtualExpression : $Fld->FldExpression;
        $lFldDataType = ($Fld->FldIsVirtual) ? EW_DATATYPE_STRING : $Fld->FldDataType;
        if ($lFldDataType == EW_DATATYPE_NUMBER) {
            $sWrk = $sFldExpression . " = " . ew_QuotedValue($Keyword, $lFldDataType);
        } else {
            $sWrk = $sFldExpression . " LIKE " . ew_QuotedValue("%" . $Keyword . "%", $lFldDataType);
        }
        if ($Where <> "")
            $Where .= " OR ";
        $Where .= $sWrk;
    }

    // Return basic search WHERE clause based on search keyword and type
    function BasicSearchWhere() {
        global $Security, $psacar_car;
        $sSearchStr = "";
        $sSearchKeyword = $psacar_car->BasicSearchKeyword;
        $sSearchType = $psacar_car->BasicSearchType;
        if ($sSearchKeyword <> "") {
            $sSearch = trim($sSearchKeyword);
            if ($sSearchType <> "") {
                while (strpos($sSearch, "  ") !== FALSE)
                    $sSearch = str_replace("  ", " ", $sSearch);
                $arKeyword = explode(" ", trim($sSearch));
                foreach ($arKeyword as $sKeyword) {
                    if ($sSearchStr <> "")
                        $sSearchStr .= " " . $sSearchType . " ";
                    $sSearchStr .= "(" . $this->BasicSearchSQL($sKeyword) . ")";
                }
            } else {
                $sSearchStr = $this->BasicSearchSQL($sSearch);
            }
        }
        if ($sSearchKeyword <> "") {
            $psacar_car->setSessionBasicSearchKeyword($sSearchKeyword);
            $psacar_car->setSessionBasicSearchType($sSearchType);
        }
        return $sSearchStr;
    }

    // Clear all search parameters
    function ResetSearchParms() {
        global $psacar_car;

        // Clear search WHERE clause
        $this->sSrchWhere = "";
        $psacar_car->setSearchWhere($this->sSrchWhere);

        // Clear basic search parameters
        $this->ResetBasicSearchParms();
    }

    // Clear all basic search parameters
    function ResetBasicSearchParms() {
        global $psacar_car;
        $psacar_car->setSessionBasicSearchKeyword("");
        $psacar_car->setSessionBasicSearchType("");
    }

    // Restore all search parameters
    function RestoreSearchParms() {
        global $psacar_car;
        $bRestore = TRUE;
        if (@$_GET[EW_TABLE_BASIC_SEARCH] <> "")
            $bRestore = FALSE;
        $this->RestoreSearch = $bRestore;
        if ($bRestore) {

            // Restore basic search values
            $psacar_car->BasicSearchKeyword = $psacar_car->getSessionBasicSearchKeyword();
            $psacar_car->BasicSearchType = $psacar_car->getSessionBasicSearchType();
        }
    }

    // Set up sort parameters
    function SetUpSortOrder() {
        global $psacar_car;

        // Check for "order" parameter
        if (@$_GET["order"] <> "") {
            $psacar_car->CurrentOrder = ew_StripSlashes(@$_GET["order"]);
            $psacar_car->CurrentOrderType = @$_GET["ordertype"];
            $psacar_car->UpdateSort($psacar_car->id); // id
            $psacar_car->UpdateSort($psacar_car->dealer_id); // dealer_id
            $psacar_car->UpdateSort($psacar_car->model_id); // model_id
            $psacar_car->UpdateSort($psacar_car->year); // year
            $psacar_car->UpdateSort($psacar_car->type_id); // type_id
            $psacar_car->UpdateSort($psacar_car->category_id); // category_id
            $psacar_car->UpdateSort($psacar_car->price); // price
            $psacar_car->UpdateSort($psacar_car->quality); // quality
            $psacar_car->UpdateSort($psacar_car->fuel); // fuel
            //$psacar_car->UpdateSort($psacar_car->rent_type); // rent_type
            //$psacar_car->UpdateSort($psacar_car->vehicle_type_id); // vehicle_type_id
            $psacar_car->setStartRecordNumber(1); // Reset start position
        }
    }

    // Load sort order parameters
    function LoadSortOrder() {
        global $psacar_car;
        $sOrderBy = $psacar_car->getSessionOrderBy(); // Get ORDER BY from Session
        if ($sOrderBy == "") {
            if ($psacar_car->SqlOrderBy() <> "") {
                $sOrderBy = $psacar_car->SqlOrderBy();
                $psacar_car->setSessionOrderBy($sOrderBy);
            }
        }
    }

    // Reset command
    // cmd=reset (Reset search parameters)
    // cmd=resetall (Reset search and master/detail parameters)
    // cmd=resetsort (Reset sort parameters)
    function ResetCmd() {
        global $psacar_car;

        // Get reset command
        if (@$_GET["cmd"] <> "") {
            $sCmd = $_GET["cmd"];

            // Reset search criteria
            if (strtolower($sCmd) == "reset" || strtolower($sCmd) == "resetall")
                $this->ResetSearchParms();

            // Reset sorting order
            if (strtolower($sCmd) == "resetsort") {
                $sOrderBy = "";
                $psacar_car->setSessionOrderBy($sOrderBy);
                $psacar_car->id->setSort("");
                $psacar_car->dealer_id->setSort("");
                $psacar_car->model_id->setSort("");
                $psacar_car->year->setSort("");
                $psacar_car->type_id->setSort("");
                $psacar_car->category_id->setSort("");
                $psacar_car->price->setSort("");
                $psacar_car->quality->setSort("");
                $psacar_car->fuel->setSort("");
                //$psacar_car->rent_type->setSort("");
                //$psacar_car->vehicle_type_id->setSort("");
            }

            // Reset start position
            $this->lStartRec = 1;
            $psacar_car->setStartRecordNumber($this->lStartRec);
        }
    }

    // Set up list options
    function SetupListOptions() {
        global $Security, $psacar_car;

//        // "view"
//        $this->ListOptions->Add("view");
//        $item = & $this->ListOptions->Items["view"];
//        $item->CssStyle = "white-space: nowrap;";
//        $item->Visible = $Security->IsLoggedIn();
//        $item->OnLeft = FALSE;

        // "edit"
        $this->ListOptions->Add("edit");
        $item = & $this->ListOptions->Items["edit"];
        $item->CssStyle = "white-space: nowrap;";
        $item->Visible = $Security->IsLoggedIn();
        $item->OnLeft = FALSE;

        // "copy"
        $this->ListOptions->Add("copy");
        $item = & $this->ListOptions->Items["copy"];
        $item->CssStyle = "white-space: nowrap;";
        $item->Visible = $Security->IsLoggedIn();
        $item->OnLeft = FALSE;

        // "delete"
        $this->ListOptions->Add("delete");
        $item = & $this->ListOptions->Items["delete"];
        $item->CssStyle = "white-space: nowrap;";
        $item->Visible = $Security->IsLoggedIn();
        $item->OnLeft = FALSE;

        // Call ListOptions_Load event
        $this->ListOptions_Load();
        if ($psacar_car->Export <> "" ||
                $psacar_car->CurrentAction == "gridadd" ||
                $psacar_car->CurrentAction == "gridedit")
            $this->ListOptions->HideAllOptions();
    }

    // Render list options
    function RenderListOptions() {
        global $Security, $Language, $psacar_car;
        $this->ListOptions->LoadDefault();

        // "view"
        $oListOpt = & $this->ListOptions->Items["view"];
        if ($Security->IsLoggedIn() && $oListOpt->Visible)
            $oListOpt->Body = "<a href=\"" . $this->ViewUrl . "\">" . "<img src=\"images/view.gif\" alt=\"" . ew_HtmlEncode($Language->Phrase("ViewLink")) . "\" title=\"" . ew_HtmlEncode($Language->Phrase("ViewLink")) . "\" width=\"16\" height=\"16\" border=\"0\">" . "</a>";

        // "edit"
        $oListOpt = & $this->ListOptions->Items["edit"];
        if ($Security->IsLoggedIn() && $oListOpt->Visible) {
            $oListOpt->Body = "<a href=\"" . $this->EditUrl . "\">" . "<img src=\"images/edit.gif\" alt=\"" . ew_HtmlEncode($Language->Phrase("EditLink")) . "\" title=\"" . ew_HtmlEncode($Language->Phrase("EditLink")) . "\" width=\"16\" height=\"16\" border=\"0\">" . "</a>";
        }

        // "copy"
        $oListOpt = & $this->ListOptions->Items["copy"];
        if ($Security->IsLoggedIn() && $oListOpt->Visible) {
            $oListOpt->Body = "<a href=\"" . $this->CopyUrl . "\">" . "<img src=\"images/copy.gif\" alt=\"" . ew_HtmlEncode($Language->Phrase("CopyLink")) . "\" title=\"" . ew_HtmlEncode($Language->Phrase("CopyLink")) . "\" width=\"16\" height=\"16\" border=\"0\">" . "</a>";
        }

        // "delete"
        $oListOpt = & $this->ListOptions->Items["delete"];
        if ($Security->IsLoggedIn() && $oListOpt->Visible)
            $oListOpt->Body = "<a" . "" . " href=\"" . $this->DeleteUrl . "\">" . "<img src=\"images/delete.gif\" alt=\"" . ew_HtmlEncode($Language->Phrase("DeleteLink")) . "\" title=\"" . ew_HtmlEncode($Language->Phrase("DeleteLink")) . "\" width=\"16\" height=\"16\" border=\"0\">" . "</a>";
        $this->RenderListOptionsExt();

        // Call ListOptions_Rendered event
        $this->ListOptions_Rendered();
    }

    function RenderListOptionsExt() {
        global $Security, $Language, $psacar_car;
    }

    // Set up starting record parameters
    function SetUpStartRec() {
        global $psacar_car;
        if ($this->lDisplayRecs == 0)
            return;
        if ($this->IsPageRequest()) { // Validate request
            if (@$_GET[EW_TABLE_START_REC] <> "") { // Check for "start" parameter
                $this->lStartRec = $_GET[EW_TABLE_START_REC];
                $psacar_car->setStartRecordNumber($this->lStartRec);
            } elseif (@$_GET[EW_TABLE_PAGE_NO] <> "") {
                $this->nPageNo = $_GET[EW_TABLE_PAGE_NO];
                if (is_numeric($this->nPageNo)) {
                    $this->lStartRec = ($this->nPageNo - 1) * $this->lDisplayRecs + 1;
                    if ($this->lStartRec <= 0) {
                        $this->lStartRec = 1;
                    } elseif ($this->lStartRec >= intval(($this->lTotalRecs - 1) / $this->lDisplayRecs) * $this->lDisplayRecs + 1) {
                        $this->lStartRec = intval(($this->lTotalRecs - 1) / $this->lDisplayRecs) * $this->lDisplayRecs + 1;
                    }
                    $psacar_car->setStartRecordNumber($this->lStartRec);
                }
            }
        }
        $this->lStartRec = $psacar_car->getStartRecordNumber();

        // Check if correct start record counter
        if (!is_numeric($this->lStartRec) || $this->lStartRec == "") { // Avoid invalid start record counter
            $this->lStartRec = 1; // Reset start record counter
            $psacar_car->setStartRecordNumber($this->lStartRec);
        } elseif (intval($this->lStartRec) > intval($this->lTotalRecs)) { // Avoid starting record > total records
            $this->lStartRec = intval(($this->lTotalRecs - 1) / $this->lDisplayRecs) * $this->lDisplayRecs + 1; // Point to last page first record
            $psacar_car->setStartRecordNumber($this->lStartRec);
        } elseif (($this->lStartRec - 1) % $this->lDisplayRecs <> 0) {
            $this->lStartRec = intval(($this->lStartRec - 1) / $this->lDisplayRecs) * $this->lDisplayRecs + 1; // Point to page boundary
            $psacar_car->setStartRecordNumber($this->lStartRec);
        }
    }

    // Load basic search values
    function LoadBasicSearchValues() {
        global $psacar_car;
        $psacar_car->BasicSearchKeyword = @$_GET[EW_TABLE_BASIC_SEARCH];
        $psacar_car->BasicSearchType = @$_GET[EW_TABLE_BASIC_SEARCH_TYPE];
    }

    // Load recordset
    function LoadRecordset($offset = -1, $rowcnt = -1) {
        global $conn, $psacar_car;

        // Call Recordset Selecting event
        $psacar_car->Recordset_Selecting($psacar_car->CurrentFilter);

        // Load List page SQL
        $sSql = $psacar_car->SelectSQL();        
        if ($offset > -1 && $rowcnt > -1)
            $sSql .= " LIMIT $offset, $rowcnt";

        // Load recordset
        $rs = ew_LoadRecordset($sSql);

        // Call Recordset Selected event
        $psacar_car->Recordset_Selected($rs);
        return $rs;
    }

    // Load row based on key values
    function LoadRow() {
        global $conn, $Security, $psacar_car;
        $sFilter = $psacar_car->KeyFilter();

        // Call Row Selecting event
        $psacar_car->Row_Selecting($sFilter);

        // Load SQL based on filter
        $psacar_car->CurrentFilter = $sFilter;
        $sSql = $psacar_car->SQL();
        $res = FALSE;
        $rs = ew_LoadRecordset($sSql);
        if ($rs && !$rs->EOF) {
            $res = TRUE;
            $this->LoadRowValues($rs); // Load row values
            // Call Row Selected event
            $psacar_car->Row_Selected($rs);
            $rs->Close();
        }
        return $res;
    }

    // Load row values from recordset
    function LoadRowValues(&$rs) {
        global $conn, $psacar_car;
        $psacar_car->id->setDbValue($rs->fields('id'));
        $psacar_car->dealer_id->setDbValue($rs->fields('dealer_id'));
        $psacar_car->model_id->setDbValue($rs->fields('model_id'));
        $psacar_car->year->setDbValue($rs->fields('year'));
        $psacar_car->external_color_id->setDbValue($rs->fields('external_color_id'));
        $psacar_car->type_id->setDbValue($rs->fields('type_id'));
        $psacar_car->category_id->setDbValue($rs->fields('category_id'));
        $psacar_car->description->setDbValue($rs->fields('description'));
        $psacar_car->price->setDbValue($rs->fields('price'));
        $psacar_car->quality->setDbValue($rs->fields('quality'));
        $psacar_car->post_by->setDbValue($rs->fields('post_by'));
        $psacar_car->post_date->setDbValue($rs->fields('post_date'));
        $psacar_car->expiration_date->setDbValue($rs->fields('expiration_date'));
        $psacar_car->number_votes->setDbValue($rs->fields('number_votes'));
        $psacar_car->total_points->setDbValue($rs->fields('total_points'));
        $psacar_car->dec_avg->setDbValue($rs->fields('dec_avg'));
        $psacar_car->whole_avg->setDbValue($rs->fields('whole_avg'));
        $psacar_car->internal_color_id->setDbValue($rs->fields('internal_color_id'));
        $psacar_car->transmission->setDbValue($rs->fields('transmission'));
        $psacar_car->legal->setDbValue($rs->fields('legal'));
        $psacar_car->import_tax->setDbValue($rs->fields('import_tax'));
        $psacar_car->drive_train->setDbValue($rs->fields('drive_train'));
        $psacar_car->door_count->setDbValue($rs->fields('door_count'));
        $psacar_car->fuel->setDbValue($rs->fields('fuel'));
        $psacar_car->vat->setDbValue($rs->fields('vat'));
        $psacar_car->destinations->setDbValue($rs->fields('destinations'));
        //$psacar_car->rent_type->setDbValue($rs->fields('rent_type'));
        //$psacar_car->vehicle_type_id->setDbValue($rs->fields('vehicle_type_id'));
        $psacar_car->is_driver->setDbValue($rs->fields('is_driver'));
        $psacar_car->image->Upload->DbValue = $rs->fields('image');
        $psacar_car->vehicle_id_number->setDbValue($rs->fields('vehicle_id_number'));
        $psacar_car->negotiate->setDbValue($rs->fields('negotiate'));
        $psacar_car->duration_type->setDbValue($rs->fields('duration_type'));
        $psacar_car->duration->setDbValue($rs->fields('duration'));
        $psacar_car->create_date->setDbValue($rs->fields('create_date'));
        $psacar_car->end_date->setDbValue($rs->fields('end_date'));
        $psacar_car->status->setDbValue($rs->fields('status'));
        $psacar_car->code->setDbValue($rs->fields('code'));
        $psacar_car->created_date->setDbValue($rs->fields('created_date'));
        $psacar_car->modified_date->setDbValue($rs->fields('modified_date'));
    }

    // Render row values based on field settings
    function RenderRow() {
        global $conn, $Security, $Language, $psacar_car;

        // Initialize URLs
        $this->ViewUrl = $psacar_car->ViewUrl();
        $this->EditUrl = $psacar_car->EditUrl();
        $this->InlineEditUrl = $psacar_car->InlineEditUrl();
        $this->CopyUrl = $psacar_car->CopyUrl();
        $this->InlineCopyUrl = $psacar_car->InlineCopyUrl();
        $this->DeleteUrl = $psacar_car->DeleteUrl();

        // Call Row_Rendering event
        $psacar_car->Row_Rendering();

        // Common render codes for all row types
        // id

        $psacar_car->id->CellCssStyle = "";
        $psacar_car->id->CellCssClass = "";
        $psacar_car->id->CellAttrs = array();
        $psacar_car->id->ViewAttrs = array();
        $psacar_car->id->EditAttrs = array();

        // dealer_id
        $psacar_car->dealer_id->CellCssStyle = "";
        $psacar_car->dealer_id->CellCssClass = "";
        $psacar_car->dealer_id->CellAttrs = array();
        $psacar_car->dealer_id->ViewAttrs = array();
        $psacar_car->dealer_id->EditAttrs = array();

        // model_id
        $psacar_car->model_id->CellCssStyle = "";
        $psacar_car->model_id->CellCssClass = "";
        $psacar_car->model_id->CellAttrs = array();
        $psacar_car->model_id->ViewAttrs = array();
        $psacar_car->model_id->EditAttrs = array();

        // year
        $psacar_car->year->CellCssStyle = "";
        $psacar_car->year->CellCssClass = "";
        $psacar_car->year->CellAttrs = array();
        $psacar_car->year->ViewAttrs = array();
        $psacar_car->year->EditAttrs = array();

        // type_id
        $psacar_car->type_id->CellCssStyle = "";
        $psacar_car->type_id->CellCssClass = "";
        $psacar_car->type_id->CellAttrs = array();
        $psacar_car->type_id->ViewAttrs = array();
        $psacar_car->type_id->EditAttrs = array();

        // category_id
        $psacar_car->category_id->CellCssStyle = "";
        $psacar_car->category_id->CellCssClass = "";
        $psacar_car->category_id->CellAttrs = array();
        $psacar_car->category_id->ViewAttrs = array();
        $psacar_car->category_id->EditAttrs = array();

        // price
        $psacar_car->price->CellCssStyle = "";
        $psacar_car->price->CellCssClass = "";
        $psacar_car->price->CellAttrs = array();
        $psacar_car->price->ViewAttrs = array();
        $psacar_car->price->EditAttrs = array();

        // quality
        $psacar_car->quality->CellCssStyle = "white-space: nowrap;";
        $psacar_car->quality->CellCssClass = "";
        $psacar_car->quality->CellAttrs = array();
        $psacar_car->quality->ViewAttrs = array();
        $psacar_car->quality->EditAttrs = array();

        // fuel
        $psacar_car->fuel->CellCssStyle = "";
        $psacar_car->fuel->CellCssClass = "";
        $psacar_car->fuel->CellAttrs = array();
        $psacar_car->fuel->ViewAttrs = array();
        $psacar_car->fuel->EditAttrs = array();

        // rent_type
        //$psacar_car->rent_type->CellCssStyle = ""; $psacar_car->rent_type->CellCssClass = "";
        //$psacar_car->rent_type->CellAttrs = array(); $psacar_car->rent_type->ViewAttrs = array(); $psacar_car->rent_type->EditAttrs = array();
        // vehicle_type_id
        //$psacar_car->vehicle_type_id->CellCssStyle = ""; $psacar_car->vehicle_type_id->CellCssClass = "";
        //$psacar_car->vehicle_type_id->CellAttrs = array(); $psacar_car->vehicle_type_id->ViewAttrs = array(); $psacar_car->vehicle_type_id->EditAttrs = array();
        if ($psacar_car->RowType == EW_ROWTYPE_VIEW) { // View row
            // id
            $psacar_car->id->ViewValue = $psacar_car->id->CurrentValue;
            $psacar_car->id->CssStyle = "";
            $psacar_car->id->CssClass = "";
            $psacar_car->id->ViewCustomAttributes = "";

            // dealer_id
            if (strval($psacar_car->dealer_id->CurrentValue) <> "") {
                $sFilterWrk = "`id` = " . ew_AdjustSql($psacar_car->dealer_id->CurrentValue) . "";
                $sSqlWrk = "SELECT `name` FROM `psacar_member`";
                $sWhereWrk = "";
                if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "")
                        $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
                }
                if ($sWhereWrk <> "")
                    $sSqlWrk .= " WHERE " . $sWhereWrk;
                $rswrk = $conn->Execute($sSqlWrk);
                if ($rswrk && !$rswrk->EOF) { // Lookup values found
                    $psacar_car->dealer_id->ViewValue = $rswrk->fields('name');
                    $rswrk->Close();
                } else {
                    $psacar_car->dealer_id->ViewValue = $psacar_car->dealer_id->CurrentValue;
                }
            } else {
                $psacar_car->dealer_id->ViewValue = NULL;
            }
            $psacar_car->dealer_id->CssStyle = "";
            $psacar_car->dealer_id->CssClass = "";
            $psacar_car->dealer_id->ViewCustomAttributes = "";

            // model_id
            if (strval($psacar_car->model_id->CurrentValue) <> "") {
                $sFilterWrk = "id = " . ew_AdjustSql($psacar_car->model_id->CurrentValue) . "";
                $sSqlWrk = "SELECT `name` FROM psacar_model";
                $sWhereWrk = "";
                if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "")
                        $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
                }
                if ($sWhereWrk <> "")
                    $sSqlWrk .= " WHERE " . $sWhereWrk;
                $rswrk = $conn->Execute($sSqlWrk);
                if ($rswrk && !$rswrk->EOF) { // Lookup values found
                    $psacar_car->model_id->ViewValue = $rswrk->fields('name');
                    $rswrk->Close();
                } else {
                    $psacar_car->model_id->ViewValue = $psacar_car->model_id->CurrentValue;
                }
            } else {
                $psacar_car->model_id->ViewValue = NULL;
            }
            $psacar_car->model_id->CssStyle = "";
            $psacar_car->model_id->CssClass = "";
            $psacar_car->model_id->ViewCustomAttributes = "";

            // year
            $psacar_car->year->ViewValue = $psacar_car->year->CurrentValue;
            $psacar_car->year->CssStyle = "";
            $psacar_car->year->CssClass = "";
            $psacar_car->year->ViewCustomAttributes = "";

            // type_id
            if (strval($psacar_car->type_id->CurrentValue) <> "") {
                $sFilterWrk = "`id` = " . ew_AdjustSql($psacar_car->type_id->CurrentValue) . "";
                $sSqlWrk = "SELECT `name` FROM `psacar_car_type`";
                $sWhereWrk = "";
                if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "")
                        $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
                }
                if ($sWhereWrk <> "")
                    $sSqlWrk .= " WHERE " . $sWhereWrk;
                $rswrk = $conn->Execute($sSqlWrk);
                if ($rswrk && !$rswrk->EOF) { // Lookup values found
                    $psacar_car->type_id->ViewValue = $rswrk->fields('name');
                    $rswrk->Close();
                } else {
                    $psacar_car->type_id->ViewValue = $psacar_car->type_id->CurrentValue;
                }
            } else {
                $psacar_car->type_id->ViewValue = NULL;
            }
            $psacar_car->type_id->CssStyle = "";
            $psacar_car->type_id->CssClass = "";
            $psacar_car->type_id->ViewCustomAttributes = "";

            // category_id
            if (strval($psacar_car->category_id->CurrentValue) <> "") {
                $sFilterWrk = "`category_id` = " . ew_AdjustSql($psacar_car->category_id->CurrentValue) . "";
                $sSqlWrk = "SELECT `category_name` FROM `psacar_category`";
                $sWhereWrk = "";
                if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "")
                        $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
                }
                if ($sWhereWrk <> "")
                    $sSqlWrk .= " WHERE " . $sWhereWrk;
                $rswrk = $conn->Execute($sSqlWrk);
                if ($rswrk && !$rswrk->EOF) { // Lookup values found
                    $psacar_car->category_id->ViewValue = $rswrk->fields('category_name');
                    $rswrk->Close();
                } else {
                    $psacar_car->category_id->ViewValue = $psacar_car->category_id->CurrentValue;
                }
            } else {
                $psacar_car->category_id->ViewValue = NULL;
            }
            $psacar_car->category_id->CssStyle = "";
            $psacar_car->category_id->CssClass = "";
            $psacar_car->category_id->ViewCustomAttributes = "";

            // price
            $psacar_car->price->ViewValue = $psacar_car->price->CurrentValue;
            $psacar_car->price->CssStyle = "";
            $psacar_car->price->CssClass = "";
            $psacar_car->price->ViewCustomAttributes = "";

            // quality
            $psacar_car->quality->ViewValue = $psacar_car->quality->CurrentValue;
            if (strval($psacar_car->quality->CurrentValue) <> "") {
                $sFilterWrk = "`code` = " . ew_AdjustSql($psacar_car->quality->CurrentValue) . "";
                $sSqlWrk = "SELECT `mileage` FROM `psacar_mileage`";
                $sWhereWrk = "";
                if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "")
                        $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
                }
                if ($sWhereWrk <> "")
                    $sSqlWrk .= " WHERE " . $sWhereWrk;
                $rswrk = $conn->Execute($sSqlWrk);
                if ($rswrk && !$rswrk->EOF) { // Lookup values found
                    $psacar_car->quality->ViewValue = $rswrk->fields('mileage');
                    $rswrk->Close();
                } else {
                    $psacar_car->quality->ViewValue = $psacar_car->quality->CurrentValue;
                }
            } else {
                $psacar_car->quality->ViewValue = NULL;
            }
            $psacar_car->quality->CssStyle = "";
            $psacar_car->quality->CssClass = "";
            $psacar_car->quality->ViewCustomAttributes = "";

            // fuel
            if (strval($psacar_car->fuel->CurrentValue) <> "") {
                $arwrk = explode(",", $psacar_car->fuel->CurrentValue);
                $sFilterWrk = "";
                foreach ($arwrk as $wrk) {
                    if ($sFilterWrk <> "")
                        $sFilterWrk .= " OR ";
                    $sFilterWrk .= "`id` = " . ew_AdjustSql(trim($wrk)) . "";
                }
                $sSqlWrk = "SELECT `fuel` FROM `psacar_fuel`";
                $sWhereWrk = "";
                if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "")
                        $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
                }
                if ($sWhereWrk <> "")
                    $sSqlWrk .= " WHERE " . $sWhereWrk;
                $rswrk = $conn->Execute($sSqlWrk);
                if ($rswrk && !$rswrk->EOF) { // Lookup values found
                    $psacar_car->fuel->ViewValue = "";
                    $ari = 0;
                    while (!$rswrk->EOF) {
                        $psacar_car->fuel->ViewValue .= $rswrk->fields('fuel');
                        $rswrk->MoveNext();
                        if (!$rswrk->EOF)
                            $psacar_car->fuel->ViewValue .= ew_ViewOptionSeparator($ari); // Separate Options
                        $ari++;
                    }
                    $rswrk->Close();
                } else {
                    $psacar_car->fuel->ViewValue = $psacar_car->fuel->CurrentValue;
                }
            } else {
                $psacar_car->fuel->ViewValue = NULL;
            }
            $psacar_car->fuel->CssStyle = "";
            $psacar_car->fuel->CssClass = "";
            $psacar_car->fuel->ViewCustomAttributes = "";

            // rent_type
//			if (strval($psacar_car->rent_type->CurrentValue) <> "") {
//				switch ($psacar_car->rent_type->CurrentValue) {
//					case "0":
//						$psacar_car->rent_type->ViewValue = "Long term leasing";
//						break;
//					case "1":
//						$psacar_car->rent_type->ViewValue = "Short term leasing";
//						break;
//					case "2":
//						$psacar_car->rent_type->ViewValue = "Tour Package";
//						break;
//					default:
//						$psacar_car->rent_type->ViewValue = $psacar_car->rent_type->CurrentValue;
//				}
//			} else {
//				$psacar_car->rent_type->ViewValue = NULL;
//			}
//			$psacar_car->rent_type->CssStyle = "";
//			$psacar_car->rent_type->CssClass = "";
//			$psacar_car->rent_type->ViewCustomAttributes = "";
            // vehicle_type_id
//			if (strval($psacar_car->vehicle_type_id->CurrentValue) <> "") {
//				switch ($psacar_car->vehicle_type_id->CurrentValue) {
//					case "0":
//						$psacar_car->vehicle_type_id->ViewValue = "Buy";
//						break;
//					case "1":
//						$psacar_car->vehicle_type_id->ViewValue = "Sale";
//						break;
//					case "2":
//						$psacar_car->vehicle_type_id->ViewValue = "Rent";
//						break;
//					default:
//						$psacar_car->vehicle_type_id->ViewValue = $psacar_car->vehicle_type_id->CurrentValue;
//				}
//			} else {
//				$psacar_car->vehicle_type_id->ViewValue = NULL;
//			}
//			$psacar_car->vehicle_type_id->CssStyle = "";
//			$psacar_car->vehicle_type_id->CssClass = "";
//			$psacar_car->vehicle_type_id->ViewCustomAttributes = "";
            // create_date
            $psacar_car->create_date->ViewValue = $psacar_car->create_date->CurrentValue;
            $psacar_car->create_date->ViewValue = ew_FormatDateTime($psacar_car->create_date->ViewValue, 5);
            $psacar_car->create_date->CssStyle = "";
            $psacar_car->create_date->CssClass = "";
            $psacar_car->create_date->ViewCustomAttributes = "";

            // end_date
            $psacar_car->end_date->ViewValue = $psacar_car->end_date->CurrentValue;
            $psacar_car->end_date->ViewValue = ew_FormatDateTime($psacar_car->end_date->ViewValue, 5);
            $psacar_car->end_date->CssStyle = "";
            $psacar_car->end_date->CssClass = "";
            $psacar_car->end_date->ViewCustomAttributes = "";

            // status
            if (strval($psacar_car->status->CurrentValue) <> "") {
                switch ($psacar_car->status->CurrentValue) {
                    case "0":
                        $psacar_car->status->ViewValue = "Pendding";
                        break;
                    case "1":
                        $psacar_car->status->ViewValue = "Approved";
                        break;
                    case "2":
                        $psacar_car->status->ViewValue = "Deleted";
                        break;
                    default:
                        $psacar_car->status->ViewValue = $psacar_car->status->CurrentValue;
                }
            } else {
                $psacar_car->status->ViewValue = NULL;
            }
            $psacar_car->status->CssStyle = "";
            $psacar_car->status->CssClass = "";
            $psacar_car->status->ViewCustomAttributes = "";

            // code
            $psacar_car->code->ViewValue = $psacar_car->code->CurrentValue;
            $psacar_car->code->CssStyle = "";
            $psacar_car->code->CssClass = "";
            $psacar_car->code->ViewCustomAttributes = "";

            // id
            $psacar_car->id->HrefValue = "";
            $psacar_car->id->TooltipValue = "";

            // dealer_id
            $psacar_car->dealer_id->HrefValue = "";
            $psacar_car->dealer_id->TooltipValue = "";

            // model_id
            $psacar_car->model_id->HrefValue = "";
            $psacar_car->model_id->TooltipValue = "";

            // year
            $psacar_car->year->HrefValue = "";
            $psacar_car->year->TooltipValue = "";

            // type_id
            $psacar_car->type_id->HrefValue = "";
            $psacar_car->type_id->TooltipValue = "";

            // category_id
            $psacar_car->category_id->HrefValue = "";
            $psacar_car->category_id->TooltipValue = "";

            // price
            $psacar_car->price->HrefValue = "";
            $psacar_car->price->TooltipValue = "";

            // quality
            $psacar_car->quality->HrefValue = "";
            $psacar_car->quality->TooltipValue = "";

            // fuel
            $psacar_car->fuel->HrefValue = "";
            $psacar_car->fuel->TooltipValue = "";

//			// rent_type
//			$psacar_car->rent_type->HrefValue = "";
//			$psacar_car->rent_type->TooltipValue = "";
//
//			// vehicle_type_id
//			$psacar_car->vehicle_type_id->HrefValue = "";
//			$psacar_car->vehicle_type_id->TooltipValue = "";
        }

        // Call Row Rendered event
        if ($psacar_car->RowType <> EW_ROWTYPE_AGGREGATEINIT)
            $psacar_car->Row_Rendered();
    }

    // Export data in HTML/CSV/Word/Excel/XML/Email format
    function ExportData() {
        global $psacar_car;
        $utf8 = TRUE;
        $bSelectLimit = EW_SELECT_LIMIT;

        // Load recordset
        if ($bSelectLimit) {
            $this->lTotalRecs = $psacar_car->SelectRecordCount();
        } else {
            if ($rs = $this->LoadRecordset())
                $this->lTotalRecs = $rs->RecordCount();
        }
        $this->lStartRec = 1;

        // Export all
        if ($psacar_car->ExportAll) {
            $this->lDisplayRecs = $this->lTotalRecs;
            $this->lStopRec = $this->lTotalRecs;
        } else { // Export one page only
            $this->SetUpStartRec(); // Set up start record position
            // Set the last record to display
            if ($this->lDisplayRecs < 0) {
                $this->lStopRec = $this->lTotalRecs;
            } else {
                $this->lStopRec = $this->lStartRec + $this->lDisplayRecs - 1;
            }
        }
        if ($bSelectLimit)
            $rs = $this->LoadRecordset($this->lStartRec - 1, $this->lDisplayRecs);
        if (!$rs) {
            header("Content-Type:"); // Remove header
            header("Content-Disposition:");
            $this->ShowMessage();
            return;
        }
        if ($psacar_car->Export == "xml") {
            $XmlDoc = new cXMLDocument(EW_XML_ENCODING);
            $XmlDoc->AddRoot();
        } else {
            $ExportDoc = new cExportDocument($psacar_car, "h");
            $ExportDoc->ExportHeader();
            if ($ExportDoc->Horizontal) { // Horizontal format, write header
                $ExportDoc->BeginExportRow();
                $ExportDoc->ExportCaption($psacar_car->model_id);
                $ExportDoc->ExportCaption($psacar_car->quality);
                $ExportDoc->ExportCaption($psacar_car->fuel);
                $ExportDoc->ExportCaption($psacar_car->vehicle_type_id);
                $ExportDoc->ExportCaption($psacar_car->create_date);
                $ExportDoc->ExportCaption($psacar_car->end_date);
                $ExportDoc->ExportCaption($psacar_car->status);
                $ExportDoc->ExportCaption($psacar_car->code);
                $ExportDoc->EndExportRow();
            }
        }

        // Move to first record
        $this->lRecCnt = $this->lStartRec - 1;
        if (!$rs->EOF) {
            $rs->MoveFirst();
            if (!$bSelectLimit && $this->lStartRec > 1)
                $rs->Move($this->lStartRec - 1);
        }
        while (!$rs->EOF && $this->lRecCnt < $this->lStopRec) {
            $this->lRecCnt++;
            if (intval($this->lRecCnt) >= intval($this->lStartRec)) {
                $this->LoadRowValues($rs);

                // Render row
                $psacar_car->CssClass = "";
                $psacar_car->CssStyle = "";
                $psacar_car->RowType = EW_ROWTYPE_VIEW; // Render view
                $this->RenderRow();
                if ($psacar_car->Export == "xml") {
                    $XmlDoc->AddRow();
                    $XmlDoc->AddField('model_id', $psacar_car->model_id->ExportValue($psacar_car->Export, $psacar_car->ExportOriginalValue));
                    $XmlDoc->AddField('quality', $psacar_car->quality->ExportValue($psacar_car->Export, $psacar_car->ExportOriginalValue));
                    $XmlDoc->AddField('fuel', $psacar_car->fuel->ExportValue($psacar_car->Export, $psacar_car->ExportOriginalValue));
                    $XmlDoc->AddField('vehicle_type_id', $psacar_car->vehicle_type_id->ExportValue($psacar_car->Export, $psacar_car->ExportOriginalValue));
                    $XmlDoc->AddField('create_date', $psacar_car->create_date->ExportValue($psacar_car->Export, $psacar_car->ExportOriginalValue));
                    $XmlDoc->AddField('end_date', $psacar_car->end_date->ExportValue($psacar_car->Export, $psacar_car->ExportOriginalValue));
                    $XmlDoc->AddField('status', $psacar_car->status->ExportValue($psacar_car->Export, $psacar_car->ExportOriginalValue));
                    $XmlDoc->AddField('code', $psacar_car->code->ExportValue($psacar_car->Export, $psacar_car->ExportOriginalValue));
                } else {
                    $ExportDoc->BeginExportRow(TRUE); // Allow CSS styles if enabled
                    $ExportDoc->ExportField($psacar_car->model_id);
                    $ExportDoc->ExportField($psacar_car->quality);
                    $ExportDoc->ExportField($psacar_car->fuel);
                    $ExportDoc->ExportField($psacar_car->vehicle_type_id);
                    $ExportDoc->ExportField($psacar_car->create_date);
                    $ExportDoc->ExportField($psacar_car->end_date);
                    $ExportDoc->ExportField($psacar_car->status);
                    $ExportDoc->ExportField($psacar_car->code);
                    $ExportDoc->EndExportRow();
                }
            }
            $rs->MoveNext();
        }
        if ($psacar_car->Export <> "xml")
            $ExportDoc->ExportFooter();

        // Close recordset
        $rs->Close();

        // Clean output buffer
        if (!EW_DEBUG_ENABLED && ob_get_length())
            ob_end_clean();

        // Write BOM if utf-8
        if ($utf8 && !in_array($psacar_car->Export, array("email", "xml")))
            echo "\xEF\xBB\xBF";

        // Write debug message if enabled
        if (EW_DEBUG_ENABLED)
            echo ew_DebugMsg();

        // Output data
        if ($psacar_car->Export == "xml") {
            header("Content-Type: text/xml");
            echo $XmlDoc->XML();
        } elseif ($psacar_car->Export == "email") {
            $this->ExportEmail($ExportDoc->Text);
            $this->Page_Terminate($psacar_car->ExportReturnUrl());
        } else {
            echo $ExportDoc->Text;
        }
    }

    // Page Load event
    function Page_Load() {

        //echo "Page Load";
    }

    // Page Unload event
    function Page_Unload() {

        //echo "Page Unload";
    }

    // Page Redirecting event
    function Page_Redirecting(&$url) {

        // Example:
        //$url = "your URL";
    }

    // Message Showing event
    function Message_Showing(&$msg) {

        // Example:
        //$msg = "your new message";
    }

    // Form Custom Validate event
    function Form_CustomValidate(&$CustomError) {

        // Return error message in CustomError
        return TRUE;
    }

    // ListOptions Load event
    function ListOptions_Load() {

        // Example: 
        //$this->ListOptions->Add("new");
        //$this->ListOptions->Items["new"]->OnLeft = TRUE; // Link on left
        //$this->ListOptions->MoveItem("new", 0); // Move to first column
    }

    // ListOptions Rendered event
    function ListOptions_Rendered() {

        // Example: 
        //$this->ListOptions->Items["new"]->Body = "xxx";
    }

}
?>
